package org.homeorganiser.flex.util;

import javax.sql.DataSource;

import org.springframework.jdbc.core.JdbcTemplate;

public class DatabaseInitializer {
	private final JdbcTemplate template;

    public DatabaseInitializer(DataSource ds) {
        this.template = new JdbcTemplate(ds);
        /*createTableUser();
        createTableLanguage();
        createTableGenre();
        createTableType();
        createTableImage();
        createTableBook();*/
        createTableInventory();
        
        createTableCategory();
        createTableSubCategory();
        createTableGenre();
        createTableLanguage();
        createTableType();
        createTableScreenShot();
        createTableQuality();
        createTableLocation();
        createTablePublication();
        createTableBook();
    }
    
    public void createTableUser() {
    	this.template.execute(Constant.SQL_CREATE_USER_TABLE);
    }
    public void createTableBook() {
    	this.template.execute(Constant.SQL_CREATE_BOOK_TABLE);
    	System.out.println("Book Table Created");
    }
    public void createTableVideo() {
    	
    }
    public void createTableSound() {
    	
    }
    public void createTableImage() {
    	
    }
    
    public void createTableInventory() {
    	this.template.execute(Constant.SQL_CREATE_INVENTORY_TABLE);
    	System.out.println("Inventory Table Created");
    }
    
    public void createTableCategory() {
    	this.template.execute(Constant.SQL_CREATE_CATEGORY_TABLE);
    	System.out.println("Category Table Created");
    }
    
    public void createTableSubCategory() {
    	this.template.execute(Constant.SQL_CREATE_SUBCATEGORY_TABLE);
    	System.out.println("SubCategory Table Created");
    }
    
    public void createTableGenre() {
    	this.template.execute(Constant.SQL_CREATE_GENRE_TABLE);
    	System.out.println("Genre Table Created");
    }
    public void createTableLanguage() {
    	this.template.execute(Constant.SQL_CREATE_LANGUAGE_TABLE); 	
    	System.out.println("Language Table Created");
    }
    public void createTableType() {
    	this.template.execute(Constant.SQL_CREATE_TYPE_TABLE); 	
    	System.out.println("Type Table Created");
    }
    public void createTableScreenShot() {
    	this.template.execute(Constant.SQL_CREATE_SCREENSHOT_TABLE); 	
    	System.out.println("ScreenShot Table Created");
    }
    public void createTableQuality() {
    	this.template.execute(Constant.SQL_CREATE_QUALITY_TABLE); 	
    	System.out.println("Quality Table Created");
    }    
    public void createTableLocation() {
    	this.template.execute(Constant.SQL_CREATE_LOCATION_TABLE); 	
    	System.out.println("Location Table Created");
    }
    public void createTablePublication() {
    	this.template.execute(Constant.SQL_CREATE_PUBLICATION_TABLE); 	
    	System.out.println("Publication Table Created");
    }
    public void truncate(String tableName){
    	this.template.execute("TRUNCATE "+tableName.toUpperCase()); 	
    	System.out.println(tableName+" Table Truncated");
    }
    
    
    
}
